package com.leosoft.heatmonitor.dao;

import java.util.List;

import org.hibernate.Criteria;
import org.hibernate.criterion.Projections;
import org.hibernate.criterion.Restrictions;
import org.springframework.stereotype.Component;

import com.leosoft.heatmonitor.model.Location;

@Component
public class LocationDAO extends BaseDAO {

	public List<String> getProvince() {
		Criteria c = this.getSession().createCriteria(Location.class);
		c.setProjection(Projections.groupProperty("province"));
		return c.list();

	}

	public List<String> getCity(String province) {
		Criteria c = this.getSession().createCriteria(Location.class);
		c = c.add(Restrictions.eq("province", province));
		c.setProjection(Projections.groupProperty("city"));
		return c.list();
	}

	public List<String> getDistrict(String province, String city) {
		Criteria c = this.getSession().createCriteria(Location.class);
		c = c.add(Restrictions.eq("province", province));
		c = c.add(Restrictions.eq("city", city));
		c.setProjection(Projections.groupProperty("district"));
		return c.list();
	}

}
